﻿using System;
using System.Web.UI.WebControls;
using CustomerContactSystem.Core.Model;

namespace CustomerContactSystem.WebForms.Admin.Classifications {
    public partial class List : BasePage {
        protected void Page_Load(object sender, EventArgs e) {
            if (Page.IsPostBack) {
                return;
            }

            GetClassifications();
        }

        private void GetClassifications() {
            var classifications = EnquiryClassificationRepository.QueryOver().OrderBy(c => c.Classification).Asc.List();
            ClassificationsList.DataSource = classifications;
            ClassificationsList.DataBind();
        }

        protected void ClassificationsListItemDataBound(object sender, RepeaterItemEventArgs e) {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) {
                return;
            }

            var classification = (EnquiryClassification)e.Item.DataItem;
            var editLink = (HyperLink) e.Item.FindControl("EditLink");
            editLink.NavigateUrl = "~/Admin/Classifications/Edit.aspx?id=" + classification.Id;
        }
    }
}